//
//  UIManager.m
//  Water
//
//  Created by reyzhang on 2021/2/2.
//  Copyright © 2021 myjs. All rights reserved.
//

#import "UIManager.h"


@interface UIManager ()
@property (nonatomic, assign, readonly) UIEdgeInsets safeAreaInset;
@end

@implementation UIManager

- (UIWindow *)keyWindow {
    return [[UIApplication sharedApplication] delegate].window;
}

- (UIEdgeInsets)safeAreaInset {
    if (@available(iOS 11.0, *)) {
        if (self.keyWindow) {
            return self.keyWindow.safeAreaInsets;
        }
    }
    return UIEdgeInsetsZero;
}



- (BOOL)isHairHead {
    if (UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) {
        return self.safeAreaInset.left > 0.0f;
    }else {
        return self.safeAreaInset.bottom > 0.f;
    }
}

- (CGFloat)safeAreaTop {
    CGFloat adjustTop =  0;
    
    //适配ios 11之后的版本 reyzhang
    if (@available(iOS 11.0, *)) {
        if (self.safeAreaInset.top == 0) {
            adjustTop = 0;
        }else {
            adjustTop = 20;
        }
    }
    
    return self.safeAreaInset.top - adjustTop;
}


- (CGFloat)safeAreaBottom {
    return self.safeAreaInset.bottom;
}

+ (instancetype)sharedManager {
    static dispatch_once_t onceToken;
    static UIManager *_manager = nil;
    dispatch_once(&onceToken, ^{
         _manager = [[UIManager alloc] init];
    });
    return _manager;
}
@end
